#!/bin/sh

make clean;
make;

#fcfs
echo "FCFS"
if [ ! -d "task1" ]; then
	mkdir task1
else
	rm -rf task1/*
fi

for rho in 0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95
do
	echo 'Run' $n 'for rho = '$rho
	./queuesimulation $rho 40 40 100000 0 0 >> task1/output_task1_fcfs
#		sleep 2
done

grep 'Average waiting time*' task1/output_task1_fcfs | grep -o '[0-9]*\.[0-9]*' | awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task1/waiting.fcfs

echo "LCFS"
for rho in 0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95
do
	echo 'Run' $n 'for rho = '$rho
	./queuesimulation $rho 40 40 100000 0 1 >> task1/output_task1_lcfs
#		sleep 2
done

grep 'Average waiting time*' task1/output_task1_lcfs | grep -o '[0-9]*\.[0-9]*' | awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task1/waiting.lcfs


echo "SJF"
for rho in 0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95
do
	echo 'Run' $n 'for rho = '$rho
	./queuesimulation $rho 40 40 100000 0 2 >> task1/output_task1_sjf
#		sleep 2
done


grep 'Average waiting time*' task1/output_task1_sjf | grep -o '[0-9]*\.[0-9]*' | awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task1/waiting.sjf


if [ ! -d "task1/prioritynp" ]; then
	mkdir task1/prioritynp
else
	rm -rf task1/prioritynp/*
fi

echo "Priority-NP"
for rho in 0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95
do
	echo 'Run' $n 'for rho = '$rho
	./queuesimulation $rho 40 40 100000 0 3 >> task1/prioritynp/output_task1_prioritynp
#		sleep 2
done

grep 'Average waiting time =' task1/prioritynp/output_task1_prioritynp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?" | awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task1/prioritynp/waiting.prioritynp

grep 'Average waiting time for queue one =' task1/prioritynp/output_task1_prioritynp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?" | awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task1/prioritynp/waiting_queue0.prioritynp

grep 'Average waiting time for queue two =' task1/prioritynp/output_task1_prioritynp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?" | awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task1/prioritynp/waiting_queue1.prioritynp

grep 'Average waiting time for queue three =' task1/prioritynp/output_task1_prioritynp |egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task1/prioritynp/waiting_queue2.prioritynp

grep 'Average waiting time for queue four =' task1/prioritynp/output_task1_prioritynp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?" | awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task1/prioritynp/waiting_queue3.prioritynp

if [ ! -d "task1/priorityp" ]; then
	mkdir task1/priorityp
else
	rm -rf task1/priority/*
fi

echo "Priority-P"
for rho in 0.05 0.15 0.25 0.35 0.45 0.55 0.65 0.75 0.85 0.95
do
	echo 'Run' $n 'for rho = '$rho
	./queuesimulation $rho 40 40 100000 0 4 >> task1/priorityp/output_task1_priorityp
#		sleep 2
done

grep 'Average waiting time =' task1/priorityp/output_task1_priorityp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?" | awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task1/priorityp/waiting.priorityp

grep 'Average waiting time for queue one =' task1/priorityp/output_task1_priorityp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task1/priorityp/waiting_queue0.priorityp

grep 'Average waiting time for queue two =' task1/priorityp/output_task1_priorityp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task1/priorityp/waiting_queue1.priorityp

grep 'Average waiting time for queue three =' task1/priorityp/output_task1_priorityp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?" | awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task1/priorityp/waiting_queue2.priorityp

grep 'Average waiting time for queue four =' task1/priorityp/output_task1_priorityp | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?" | awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' >> task1/priorityp/waiting_queue3.priorityp

